<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<div th:replace="dashboard/header :: header"></div>

<body id="page-top">

	<div id="wrapper">
		<div id="content-wrapper">
			<div class="container-fluid">

				<ol class="breadcrumb">
					<li class="breadcrumb-item"><a href="#">部署管理</a></li>
				</ol>

				<form class="form-inline" id="trainingSearchForm">
					<div class="input-group mb-2 mr-sm-2">
						<select name="condition[masterCode]" style="width: 200px"
							id="inputState" class="form-control">
							<option th:each="m:${schools}" th:text="${m.masterName}"
								th:value="${m.masterCode}"></option>
						</select>
					</div>
					<label class="sr-only" for="inlineFormInputName2">Name</label> <input
						type="text" class="form-control mb-2 mr-sm-2" id="orderId"
						name="condition[orderId|like]" placeholder="订单号"> <label
						class="sr-only" for="inlineFormInputGroupUsername2">Username</label>

					<div class="input-group mb-2 mr-sm-2">
						<select name="condition[sendStatus]" id="inputState"
							class="form-control">
							<option value="">状态</option>
							<option value="01">未接单</option>
							<option value="02">已接单</option>
							<option value="04">已签收</option>
							<option value="05">订单超时</option>
						</select>
					</div>

					<button type="button" onclick="search(this)"
						class="btn btn-primary mb-2">搜索</button>
				

				</form>
				<div class="span12">
					<div class="table-responsive">
						<table class="table table-bordered" id="dataTable" width="100%"
							cellspacing="0">
							<thead>
								<tr>
									<th style="width: 150px">所属机房</th>
									<th>服务器IP</th>
									<th style="max-width: 200px">服务用途</th>
									<th>配置</th>
									<th>申请源</th>
									<th>起止时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
							<footer>
								<tr>
									<th style="width: 150px">所属机房</th>
									<th>服务器IP</th>
									<th style="max-width: 200px">服务用途</th>
									<th>配置</th>
									<th>申请源</th>
									<th>起止时间</th>
									<th>操作</th>
								</tr>
							</footer>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="http://training-static.linesno.com/vendor/jquery/jquery.min.js"></script>
	<script src="http://training-static.linesno.com/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
	<script src="http://training-static.linesno.com/layer/layer.js"></script>
	<script src="http://training-static.linesno.com/vendor/jquery-easing/jquery.easing.min.js"></script>
	<script src="http://training-static.linesno.com/vendor/datatables/jquery.dataTables.js"></script>
	<script src="http://training-static.linesno.com/vendor/datatables/dataTables.bootstrap4.js"></script>

	<script type="text/javascript">
		$(document).ready(function() {
		  $('#dataTable').DataTable({
			  serverSide: true ,
			  ordering: false , 
			  searching : false ,
              bLengthChange : false ,
              rowNum : 15 , 
              multiselect : true,
              ajax : {
                  "url": "/manager/deploy_list_data",
                  "dataType": "json" ,
                  "data": function (d) {
                      console.log('d = ' + d) ;
                      var searchParams = paramsBuilder() ;
                      if(searchParams){
                        $.extend(d,searchParams); 
                      }
                  }
              } ,
              columns: [
                  { data: 'masterCode_label' },
                  { data: 'machineIp' },
                  { data: 'goodsName' },
                  { data: 'orderStorage' },
                  { data: 'receiveAddress' },
                  { data: 'endTime' },
                  { data: 'id' }
              ] , 
              columnDefs : [
            	  {
					   "targets" : 1,//操作按钮目标列
					   "data" : null,
					   "render" : function(data, type,row) {
						   var id = row.orderId ; 
						   var html = "<a style='cursor:pointer;' data-id="+id+" data-scope='runman' onclick='sendAll(this)'>"+data+"</a>" ; 
						   return html;
					  }
            	  },
            	  {
					   "targets" : 6,//操作按钮目标列
					   "data" : null,
					   "render" : function(data, type,row) {
						   var id = row.id ; 
						   var html = "<a style='cursor:pointer' data-id="+id+" onclick='showDetail(this)'><i class='fa fa-leaf'></i> 停止</a>" ; 
						   html += "<a style='cursor:pointer;margin-left:10px;color:red' data-id="+id+" onclick='deleteOrder(this)'><i class='fa fa-trash'></i> 删除</a>" ; 
						   return html;
						}
				  }
            	  ],
              language : {
                  "sProcessing": "处理中...",
                  "sLengthMenu": "显示 _MENU_ 项结果",
                  "sZeroRecords": "没有匹配结果",
                  "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                  "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                  "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                  "sInfoPostFix": "",
                  "sSearch": "搜索:",
                  "sUrl": "",
                  "sEmptyTable": "表中数据为空",
                  "sLoadingRecords": "载入中...",
                  "sInfoThousands": ",",
                  "oPaginate": {
                      "sFirst": "首页",
                      "sPrevious": "上页",
                      "sNext": "下页",
                      "sLast": "末页"
                  },
                  "oAria": {
                      "sSortAscending": ": 以升序排列此列",
                      "sSortDescending": ": 以降序排列此列"
                  }
             }

		  });
		});
		
		//搜索
		function search(btn){
			// $('#dataTable').draw();
			$("#dataTable").dataTable().fnDraw(false);
		}
		
		/**
		 * get params
		 */
		function paramsBuilder() {
		    var param = {} ;
		    $('#trainingSortPanel input').each(function() {
		        if ($(this).val() != '' && this.name != '') {
		            param[this.name] = this.value;
		        }

		    });
		    var i = $('#trainingSearchForm input') ; 
		    console.log("i = " + i) ; 
		    $('#trainingSearchForm input').each(function() {
		        if ($(this).val() != '' && this.name != '') {
		            param[this.name] = this.value;
		        }

		    });
		    $('#trainingSearchForm select').each(function() {
		        console.log('value = ' + this.value + ' , value = ' + $(this).val());
		        if ($(this).val() != null &&  $(this).val() != '' && this.name != '') {
		            param[this.name] = $(this).val() ;
		        }
		    });
		    return param ;
		}
		
		function showDetail(btn){
			
			var orderId = $(btn).attr("data-id") ; 
			var i = layer.prompt({title: '分配IP', formType: 0}, function(text, index){
				var remark = $("#remark").val() ; 
				readNameDoing = true ; 
				
				$.post("/manager/deploy_apply_pass" , {orderInfoId :orderId , machineIp :text} , function(response){
					readNameDoing = false ; 
					
					if(response.code == 200){
						layer.close(i) ; 
						$(btn).html(response.data) ; 
						$(btn).removeAttr("onclick") ; 
						
						$("#dataTable").dataTable().fnDraw(false);
					}else{
						layer.msg(response.message) ; 
					}
					
				}) ; 
				
			});	
			
			/*
			var orderId = $(btn).attr("data-id") ; 
			layer.confirm("确定是否通过?", {
				  btn: ['通过','取消'] //按钮
			}, function(){
				$.get("/manager/deploy_apply_pass?orderInfoId="+orderId , function(response){
					  layer.msg(response.message, {icon: 1});
					  $("#dataTable").dataTable().fnDraw(false);
				}) ; 
			});
			*/
			
		}
		
		function deleteOrder(btn){
			var orderId = $(btn).attr("data-id") ; 
			layer.confirm("确定是否删除?", {
				  btn: ['删除','取消'] //按钮
				}, function(){
				 	
					$.get("/manager/deploy_delete?orderId="+orderId , function(response){
						  layer.msg(response.message, {icon: 1});
						  $("#dataTable").dataTable().fnDraw(false);
					  }) ; 
				  
				});
		}
		
		function addDb(){
			layer.open({
				  type: 2,
				  title: false,
				  shade: 0.8, 
				  title: '添加',
				  area: ['50%', '80%'],
				  content: ['/manager/database_apply', 'yes'], //iframe的url，no代表不显示滚动条
				  end: function(){ 
				     console.log("close") ; 
					 $("#dataTable").dataTable().fnDraw(false);
				  }
				});
		}
		
		function add(btn){
			layer.open({
				  type: 2,
				  title: false,
				  shade: 0.8, 
				  title: '添加',
				  area: ['50%', '80%'],
				  content: ['/manager/deploy_add', 'yes'], //iframe的url，no代表不显示滚动条
				  end: function(){ 
				     console.log("close") ; 
					 $("#dataTable").dataTable().fnDraw(false);
				  }
				});
		}
		
		function sendAll(btn){
			var orderId = $(btn).attr("data-id") ; 
			layer.confirm("确认是否需要群发,群发所有人都会收到,请确认操作", {
				  btn: ['','会员'] //按钮
				}, function(){
					
					var scope = 'runman' ; //$(btn).attr("data-scope") ; 
				  	$.get("/manager/deploy_send_all?orderId="+orderId+"&scope="+scope , function(response){
						  layer.msg(response.message, {icon: 1});
				  	}) ; 
				  
				} , function(){
					
					var scope = 'all' ; //$(btn).attr("data-scope") ; 
				  	$.get("/manager/deploy_send_all?orderId="+orderId+"&scope="+scope , function(response){
						  layer.msg(response.message, {icon: 1});
				  	}) ; 
				});
		}
		
	</script>

</body>

</html>
